package com.paic.mhis.hcpms.common.sso.intergration.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.paic.mhis.hcpms.common.sso.dto.CognosReportDTO;
import com.paic.mhis.hcpms.common.sso.dto.CognosRoleDTO;
import com.paic.mhis.hcpms.common.sso.intergration.dao.CognosReportDAO;
import com.paic.pafa.biz.dao.BaseDAO;
import com.paic.pafa.exceptions.BusinessException;

@Component("cognosReportDAOImpl")
public class CognosReportDAOImpl extends BaseDAO implements CognosReportDAO {

	@Override
	public List<CognosReportDTO> queryCognosReportDTO(Map<String, Object> parameter) {

		List<CognosReportDTO> list = (List<CognosReportDTO>) this._queryForList("cognosReport.queryReportInfo",
				parameter);
		return list;
	}

	@Override
	public long queryCognosReportCount(Map<String, Object> parameter) {

		long count = this._queryForCount("cognosReport.queryReportInfoCount", parameter);
		return count;
	}

	@Override
	public List<CognosReportDTO> findCognosReports(Map<String, Object> paramMap) throws BusinessException {
		return (List<CognosReportDTO>) this._list("cognosReport.cognosReportAuthorize", paramMap);
	}

	@Override
	public void saveCognosReportInfo(CognosReportDTO bean) {

		this._insert("cognosReport.insertCognosReportInfo", bean);
	}

	@Override
	public void updateCognosReportInfo(CognosReportDTO bean) {

		this._update("cognosReport.updateCognosReportInfo", bean);

	}

	@Override
	public void deleteCognosReportInfo(CognosReportDTO bean) {

		this._delete("cognosReport.deleteCognosReportInfo", bean);

	}

	@Override
	public List<CognosReportDTO> loadSigleCognosReportDTOInfo(Map<String, Object> parameter) {
		List<CognosReportDTO> list = (List<CognosReportDTO>) this._queryForList(
				"cognosReport.querySigleCognosReportInfo", parameter);
		return list;
	}

	@Override
	public long countSigleCognosReportDTOInfo(Map<String, Object> parameter) {
		long count = this._queryForCount("cognosReport.querySigleCognosReportInfoCount", parameter);
		return count;
	}

	@Transactional
	@Override
	public void saveCognosReportAuthorize(List<CognosRoleDTO> cognosRoles) {
		if (cognosRoles != null) {
			for (CognosRoleDTO bean : cognosRoles) {
				this._insert("cognosReport.cognosReportAuthorizeRole", bean);
			}

		}

	}

	@Override
	public List<CognosRoleDTO> cognosReportQueryRole(Map<String, Object> paramMap) throws BusinessException {
		return (List<CognosRoleDTO>) this._list("cognosReport.cognosReportQueryRole", paramMap);
	}

	@Override
	public List<CognosReportDTO> cognosReportAuthorizeQuery(Map<String, Object> paramMap) throws BusinessException {
		return (List<CognosReportDTO>) this._list("cognosReport.cognosReportAuthorizeQuery", paramMap);
	}

	@Override
	public void deleteCognosReportRole(Map<String, Object> paramMap) {
		this._delete("cognosReport.cognosReportAuthorizeDelete", paramMap);
	}

	@Override
	public List<CognosReportDTO> queryCognosReportDTOByRoleId(String roleId) {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("roleId", roleId);

		List<CognosReportDTO> list = (List<CognosReportDTO>) this._queryForList("cognosReport.queryAllReportByRoleId",
				map);
		return list;
	}

	@Override
	public List<CognosRoleDTO> queryAllRoleInfo() {
		Map<String, Object> map = new HashMap<String, Object>();
		List<CognosRoleDTO> list = (List<CognosRoleDTO>) this._queryForList("cognosReport.queryAllRole", map);
		return list;
	}
}
